package com.example.feifei.mvp.view;

import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.example.feifei.mvp.persenter.LoginPresenterCompl;
import com.example.feifei.newproject.R;

/**
 * Created by Administrator on 2018\9\17 0017.
 */

public class LoginActivity extends Activity implements View.OnClickListener,LoginView{

    private Button btn_mvpLogin;
    private Button btn_cancel;
    private EditText edit_userName,edit_pwd;
    private LoginPresenterCompl presenterCompl;
    private TextView tv_result;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_mvp_login);
        initView();
    }

    private void initView() {
        edit_userName = (EditText) this.findViewById(R.id.edit_userName);
        edit_pwd = (EditText) this.findViewById(R.id.edit_pwd);
        btn_mvpLogin = (Button) this.findViewById(R.id.btn_mvpLogin);
        btn_cancel = (Button) this.findViewById(R.id.btn_cancel);
        tv_result = (TextView) this.findViewById(R.id.tv_result);
        btn_cancel.setOnClickListener(this);
        btn_mvpLogin.setOnClickListener(this);
        presenterCompl = new LoginPresenterCompl(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            //登录按钮
            case R.id.btn_mvpLogin:
                presenterCompl.doLogin("哈哈","嗯嗯");
                break;
                //取消
            case R.id.btn_cancel:
                presenterCompl.deCancel();
                break;
        }
    }

    @Override
    public void cancel() {
        edit_pwd.setText("进行了取消操作");
    }

    /**
     * 登陆成功后的处理，只处理页面逻辑，网络请求的业务逻辑不在此处理
     * @param loginResult
     */
    @Override
    public void doLogin(String loginResult) {
        edit_userName.setText("登录操作");
        tv_result.setText(loginResult);
    }
}
